package com.lagou.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.autoconfigure.PageHelperProperties;
import com.lagou.pojo.Article;
import com.lagou.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.awt.print.Pageable;
import java.util.List;

@Controller
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @RequestMapping("/")
    public String toIndex(Model model, @RequestParam(defaultValue = "1") Integer pageNo) {
        Page<Object> page = PageHelper.startPage(pageNo, 3);
        List<Article> articleList = articleService.findAll();
        model.addAttribute("articles",articleList);
        model.addAttribute("page",page);
        return "index";
    }
}
